package net.hctek.identity.action;

import java.io.PrintWriter;
import java.net.Socket;
import java.util.HashMap;

import javax.servlet.ServletContext;

import net.hctek.identity.util.PropertyUtil;



public class ProcessSocketData extends Thread {

	private Socket socket;
	private ServletContext servletContext;
	private String ip;
	public HashMap<String,String> qrcodeDataProperties = new HashMap<>();
	
	public ProcessSocketData(){
		super();
	}
	
	public ProcessSocketData(Socket socket,ServletContext servletContext,String ip){
		this.socket = socket;
		this.servletContext = servletContext;
		this.ip = ip;
	}
	
	public void run(){
		try {
			PropertyUtil propertyUtil = new PropertyUtil();
			//服务器接收客户端消息
/*			BufferedReader br = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
			String request = br.readLine();
			System.out.println("服务器接收到:"+request);*/
			//服务器推送消息
			PrintWriter pw = new PrintWriter(socket.getOutputStream());
			while (true) {
				qrcodeDataProperties = propertyUtil.getProperty("ipAddress");
				if(ip.matches(".*"+qrcodeDataProperties.get("ipAddress")+".*")){
					qrcodeDataProperties = propertyUtil.getProperty("songName");
					pw.println(qrcodeDataProperties.get("songName").toString());
					pw.flush();
					propertyUtil.setProperty("ipAddress", "127.0.0.1");
				}
				Thread.sleep(1000);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
